from threading import Thread
import time
def sing(num,name):
    for i in range(3):
        print(f"({num}).{name}在唱歌")
        time.sleep(1)

def dance(num,name):
    for i in range(3):
        print(f"({num}).{name}在跳舞")
        time.sleep(1)

if __name__ == '__main__':
    t1 = Thread(target=sing,args=(1,),kwargs={"name":"张三"})
    # 守护线程 setDaemon()：当主线程执行完毕之后子线程回跟着死亡不会执行完
    # t1.setDaemon(True)  # True代表设置为守护线程
    t1.start()
    t2 = Thread(target=dance, args=(2,), kwargs={"name": "张三"})
    # t2.setDaemon(True)
    t2.start()
    # 阻塞主线程 join()：等待子线程执行完之后再执行主线程 放在start()后面写
    # t1.join()
    # t2.join()
    # print("hello")
    # print("world")
    # 设置线程名
    t1.setName("线程1")
    t2.setName("线程2")
    # 获取线程名
    print(t1.getName())
    print(t2.getName())


# 多任务：提高程序执行效率